home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_07_08
/
v7n8058a.txt
< prev
next >
Wrap
Text File
|
1989-03-20
|
635b
|
28 lines
#define BLOCK_SIZE 10
#define NOT_YET -1.0
float mv_avg( unsigned int sample )
{
static int ptr = 0;
static int count = 1;
static long total = 0;
static unsigned int block[BLOCK_SIZE - 1];
if( count == BLOCK_SIZE ) /* start returning averaged
results on Nth sample */
{
total += sample - block[ptr];
block[ptr] = sample;
ptr = ( ptr < BLOCK_SIZE - 1 ) ? ptr++ : 0;
return ( ( float ) total / BLOCK_SIZE );
}
else
{
count++;
block[ptr++] = sample;
total += sample;
return ( NOT_YET );
}
}